package cn.foolishbird.crow.mybatis.plus.typehandler;

import cn.foolishbird.crow.core.Cash;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author  foolish-bird
 */
@MappedTypes(Cash.class)
@MappedJdbcTypes(JdbcType.BIGINT)
public class CashTypeHandler extends BaseTypeHandler<Cash> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Cash cash, JdbcType jdbcType) throws SQLException {
        preparedStatement.setLong(i, cash.getCash());
    }

    @Override
    public Cash getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return new Cash(resultSet.getLong(s));
    }

    @Override
    public Cash getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return new Cash(resultSet.getLong(i));
    }

    @Override
    public Cash getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return new Cash(callableStatement.getLong(i));
    }
}
